{%- set image = salt['pillar.get']('default:OMV_OWNTONE_APP_CONTAINER_IMAGE', 'lscr.io/linuxserver/daapd:latest') -%}
{%- set uname = salt['pillar.get']('default:OMV_OWNTONE_APP_CONTAINER_UNAME', 'owntone') -%}
{%- set gname = salt['pillar.get']('default:OMV_OWNTONE_APP_CONTAINER_GNAME', 'users') -%}
{%- set options = salt['pillar.get']('default:OMV_OWNTONE_APP_CONTAINER_START_OPTIONS', '') -%}
{%- set uid = salt['user.info'](uname).uid -%}
{%- set gid = salt['group.info'](gname).gid -%}
{%- set sf_path = salt['omv_conf.get_sharedfolder_path'](config.sharedfolderref) -%}
{%- set sf_mnt_path = salt['omv_conf.get_sharedfolder_mount_path'](config.sharedfolderref) -%}
{{ pillar['headers']['multiline'] -}}
[Unit]
Description=OwnTone container
Wants=network.target
After=network-online.target
RequiresMountsFor="{{ sf_mnt_path }}"

[Service]
Environment=PODMAN_SYSTEMD_UNIT=%n
Restart=on-failure
TimeoutStopSec=70
ExecStartPre=/bin/rm -f %t/container-owntone.pid %t/container-owntone.ctr-id
ExecStart=/usr/bin/podman run --conmon-pidfile %t/container-owntone.pid --cidfile %t/container-owntone.ctr-id --cgroups=no-conmon -d --replace --pull=never --name=owntone --net=host -e PUID={{ uid }} -e PGID={{ gid }} -e TZ="{{ timezone }}" -v /var/cache/owntone/:/config/ -v "{{ sf_path }}":/music/ {{ options }} {{ image }}
ExecStop=/usr/bin/podman stop --ignore --cidfile %t/container-owntone.ctr-id
ExecStopPost=/usr/bin/podman rm --ignore -f --cidfile %t/container-owntone.ctr-id
PIDFile=%t/container-owntone.pid
Type=forking

[Install]
WantedBy=multi-user.target default.target
